<template>
    <div class="todoMain">
        <ul>
            <li v-for="item in list" :key="item.id">
                <div class='content'>
                    <input type="checkbox" v-model="item.isCheck">
                    <span :class='{active: item.isCheck}'>{{item.name}}</span> 
                </div>  
                <button @click='delFn(item.id)'>删除</button>
            </li>
            <!-- 任务列表为空时 显示 -->
            <li v-if='list.length === 0' class="cue">
                暂时没有任务啦!
            </li>
        </ul> 
    </div>
</template>

<script>
    export default {
        props:['list'],

        methods:{
            // 将id传到父组件 删除对应id数据
            delFn(id){
                this.$emit('delete', id)
            }
        }
    }
</script>

<style scoped>
.todoMain{
    margin: 0;
}
ul{
    list-style: none;
    padding: 0;
    margin: 0;
}
li{
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px;
    height: 50px;
    font-size: 22px;
    border-bottom: 1px solid #ccc;
}
.content, span{
    margin-left: 10px;
    font-size: 22px;
}
button{
    float: right;
    /* 隐藏 */
    display: none;
    margin-right: 10px;
}
/* 鼠标覆盖 显示button标签 */
li:hover button{
    display: inline-block;
}

li .active{
    text-decoration: line-through;
}
.cue{
    text-align: center;
}
</style>